#ifndef __CC_QUEUE__
#define __CC_QUEUE__
#include "cc_mempool.h"
#include "cc_portable.h"

typedef int (*cc_mn_callback)(int event, struct cc_mnode* mn);

// 提供一个发送节点给用户，方便进行队列的发送
typedef struct cc_mnode
{
  // 这个节点来自哪个内存池
  cc_mempool_t srchdl;
  cc_mn_callback callback;
  void* user_data;
  uint32_t src_port_id;
  uint8_t mem[0];
} cc_mnode, *cc_mnode_t;

#define MNODE_HSZ_ADD(sz) (sizeof(struct cc_mnode) + sz)

#define GET_QUEUE_STORAGE_SIZE(length, size) (length * size)

void cc_queue_init(cc_que_t que, uint8_t* que_storage_arr, uint32_t num,
                   uint32_t size);
cc_que_t cc_queue_create(uint32_t num, uint32_t size);

int cc_queue_send_time(cc_que_t que, const void* msg, TickType_t ms);
int cc_queue_send(cc_que_t que, const void* msg);
int cc_queue_send_try(cc_que_t que, const void* msg);
int cc_queue_send_urgent_time(cc_que_t que, const void* msg, TickType_t ms);
int cc_queue_send_urgent_try(cc_que_t que, const void* msg);
int cc_queue_send_urgent(cc_que_t que, const void* msg);
int cc_queue_send_overwrite(cc_que_t que, const void* msg);

int cc_queue_recv_time(cc_que_t que, void* buf, TickType_t ms);
int cc_queue_recv(cc_que_t que, void* buf);
int cc_queue_recv_try(cc_que_t que, void* buf);

void cc_queue_deinit(cc_que_t que);
void cc_queue_destory(cc_que_t que);

struct cc_mnode* cc_mnode_get(cc_mempool_t hdl, void* mem, size_t sz,
                              uint32_t timeout, cc_mn_callback cb);
int cc_mnode_put(struct cc_mnode* node);
#endif